package com.ph.myblog.action;

import java.util.List;

import com.opensymphony.xwork2.ActionSupport;
import com.ph.myblog.entity.Article;
import com.ph.myblog.entity.Articletype;
import com.ph.myblog.services.ArticleServices;
import com.ph.myblog.services.ArticleTypeServices;

public class ArticleAction extends ActionSupport {

	private Article article;
	private List<Article> articlelist;
	private Articletype type;
	private List<Articletype> typelist;
	private ArticleServices articleservices = new ArticleServices();
	private ArticleTypeServices typeservices = new ArticleTypeServices();

	public String list() throws Exception {

		articlelist = this.articleservices.list();
		return this.SUCCESS;
	}

	public String add() throws Exception {

		article.setType(type);
		this.articleservices.add(article);
		return "add_success";
	}

	public String update() throws Exception {
		this.articleservices.update(article);
		return "update_success";
	}

	public String delete() throws Exception {
		this.articleservices.delete(article);
		return "delete_success";
	}

	public String addInput() throws Exception {
		typelist = this.typeservices.list();
		return "add_input";
	}
	
	public String updateInput() throws Exception {
		article = this.articleservices.loadBlogById(article);
		return "update_input";
	}

	public Article getArticle() {
		return article;
	}

	public void setArticle(Article article) {
		this.article = article;
	}
 
	public List<Article> getArticlelist() {
		return articlelist;
	}

	public void setArticlelist(List<Article> articlelist) {
		this.articlelist = articlelist;
	}

	public ArticleServices getArticleservices() {
		return articleservices;
	}

	public void setArticleservices(ArticleServices articleservices) {
		this.articleservices = articleservices;
	}

	public ArticleTypeServices getTypeservices() {
		return typeservices;
	}

	public void setTypeservices(ArticleTypeServices typeservices) {
		this.typeservices = typeservices;
	}

	public Articletype getType() {
		return type;
	}

	public void setType(Articletype type) {
		this.type = type;
	}

	public List<Articletype> getTypelist() {
		return typelist;
	}

	public void setTypelist(List<Articletype> typelist) {
		this.typelist = typelist;
	}
	
}
